<?php

namespace App\Console\Commands;

use App\Models\Currency;
use Illuminate\Console\Command;
use App\Models\Wallet;
use App\Library\OBA\ObaFunction;

/**
 * 创建十个OBA系统钱包地址
 */
class MakeObaWallet extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'make:obawallet';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $oba = new ObaFunction();
        $cid = Currency::where('name_en', 'OBA')->value('id');
        for($i = 0; $i < 11; $i++) {
            $res = $oba->createWalletAddress();
            if ($res) {
                Wallet::create([
                    'cid' => $cid,
                    'address' => $res->wallet_addr,
                    'balance' => 0,
                    'block_balance' => 0,
                    'grand_recharge' => 0,
                    'private_key' => $res->private_key,
                    'public_key' => $res->public_key,
                    'wif_key' => $res->wif,
                    'ucomp_pub_key' => $res->ucomp_pub_key,
                    'pub_key_x' => $res->pub_key_x,
                    'pub_key_y' => $res->pub_key_y,
                    'uncomp_address' => $res->uncomp_address,
                ]);
            }
        }
    }
}
